# -*- coding: utf-8 -*-
'''
Created on 2012-06-15

@author: alexandre
'''
from mlEval.util import readFile
from os import path
from mlEval.pbTest import pbTest
from mlEval.report import unparseLossLDD

# load the example loss file
try: exampleDir = path.dirname( path.abspath( __file__ ) )
except NameError : exampleDir = '.'
lossLDD,wL = unparseLossLDD( readFile( exampleDir, 'lossLDD.txt') ) 
# lossLDD[dsName][algoName][testIdx] represents the loss of the classifier trained by [algoName] on [dsName] 
# and evaluated on test example [testIdx].
# LDD stands for List Dict Dict which represent the structure of this object


algo1 = 'svm' # support vector machine
algo2 = 'ann' # artificial neural network

# build the loss difference between two algorithms for each dataset
diffLD = {}
for dsName, lossLD in lossLDD.items():
    diffLD[dsName] = lossLD[algo1] - lossLD[algo2]

pD, pAvsB = pbTest(diffLD)

print "%s is better than %s with probability %.3f"%(algo1, algo2, pAvsB)
